package com.wesh.uaa.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Objects;

public class JacksonUtil {

    private static ObjectMapper objectMapper;

    public static ObjectMapper getInstance(){
        if(Objects.isNull(objectMapper)){
            synchronized (Object.class){
                if(Objects.isNull(objectMapper)){
                    objectMapper = new ObjectMapper();
                }
            }
        }
        return objectMapper;
    }

    public static String beanToJson(Object bean) throws JsonProcessingException {
        return getInstance().writeValueAsString(bean);
    }

}
